<template>
  <div class="gl_contentBox gl_heightFull noPadding">
    <div class="top_title">{{ title }}</div>
    <div class="gl_px_15 gl_pb_15">
      <el-row class="gl_my_15">
        <el-button type="primary" size="mini" :loading="btnLoading" @click="exportScore">成绩导出</el-button>
      </el-row>
      <el-table v-loading="loading" class="gl_table_noBorder" :data="tableData" size="mini">
        <el-table-column label="序号" type="index" />>
        <el-table-column label="姓名" align="center" width="54">
          <template slot-scope="{row}">
            <PersonalImage :imgurl="row.imagePath" imgheight="60px" />
          </template>
        </el-table-column>
        <el-table-column label="" min-width="100">
          <template slot-scope="{row}">
            {{ row.studentName || '--' }}
          </template>
        </el-table-column>
        <el-table-column label="证件号" prop="idCardNumber" :width="150" />
        <el-table-column label="联系方式" prop="phoneNumber" :width="100" />
        <el-table-column label="当前级别" :min-width="80">
          <template slot-scope="{ row }">
            <span v-if="row.levelType && row.duanType">{{ row.levelType.name + ' / ' + row.duanType.name }}</span>
            <span v-else>{{ row.levelType ? row.levelType.name : '' }} {{ row.duanType ? row.duanType.name : '' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="申报级别" :min-width="80">
          <template slot-scope="{row}">
            <span v-for="(item, index) in row.duanExamStudentDuans" :key="item.duanId">
              {{ item.duan ? item.duan.name : '' }} {{ row.duanExamStudentDuans.length - 1 === index ? '': '/' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="教练" prop="coachName" :min-width="80" />
        <el-table-column label="机构" prop="organizationUnitName" :min-width="120" />
        <el-table-column label="成绩" prop="score" />
        <el-table-column label="考官" prop="duanExamOfficialName" :min-width="80" />
        <el-table-column label="证书编号" prop="certificateNumber" :min-width="100" />
        <el-table-column label="审核结果">
          <template slot-scope="{row}">
            {{ row.toScoreStatus ? row.toScoreStatus.name : '' }}
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-row class="gl_mt_15" style="text-align: right;">
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="qo.MaxResultCount"
          :current-page="qo.Page"
          @size-change="changePageSize"
          @current-change="changePage"
        />
      </el-row>
    </div>
  </div>
</template>

<script>
import PersonalImage from '@/components/PersonalImage/index';
import { mapState, mapActions } from 'vuex';
import { errorText } from '@/lib';
import { api_GET_DownLoadFileAddHeader } from '@/extend/api/file';
import {
  Api_GET_ClubDuanExamStudentScoreExamReportStudentScoreQO // 获取考试的学生上传完成绩单之后的成绩
} from '@/lib/form/hall/swaggerForm';
import {
  api_GET_ClubDuanExamStudentScoreExamReportStudentScore // 获取考试的学生上传完成绩单之后的成绩
} from '@/extend/api/hallswaggerApi/app';
export default {
  components: {
    PersonalImage
  },
  data () {
    return {
      title: '',
      qo: new Api_GET_ClubDuanExamStudentScoreExamReportStudentScoreQO(),
      tableData: [],
      loading: false,
      total: 0,
      chooseTime: [],
      btnLoading: false,
      duanExamId: '',
      isDeclare: false
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      user: state => state.user.currentOU
    })
  },
  created() {
    this.getDict();
    this.duanExamId = this.$route.query.duanExamId || this.$route.query.id || '';
    this.title = this.$route.query.name || '';
    if (this.$route.query.id) {
      this.isDeclare = true;
    } else {
      this.isDeclare = false;
    }
    this.getPageList();
  },
  methods: {
    // 若没有字典信息，外部可直接调用方法获取字典数据
    ...mapActions({ getDict: 'dict/getDict' }),
    getPageList(page) {
      this.qo.Page = page || 1;
      this.qo.SkipCount = (this.qo.Page - 1) * this.qo.MaxResultCount;
      this.qo.DuanExamId = this.duanExamId;
      this.qo.OrganizationUnitId = this.isDeclare ? '' : this.user;
      this.qo.IncludeRegisterStudent = true;
      this.qo.IncludeDuanExamOfficial = true;
      this.qo.IncludeLevelType = true;
      this.qo.IncludeDuanType = true;
      this.qo.IncludeMemberFeeType = true;
      this.qo.IncludeDuanExamRequestDuans = true;
      this.qo.IncludeScoreStatus = true;
      this.qo.IncludeToScoreStatus = true;
      this.qo.IsApproved = true;
      this.qo.ScoreStatusCode = 'Approved';
      this.qo.IncludeDuanExamFees = true;
      this.qo.IsCurrentOrgStudentScore = !this.isDeclare;
      this.qo.Sorting = 'creationTime DESC';
      this.loading = true;
      api_GET_ClubDuanExamStudentScoreExamReportStudentScore(this.qo).then(res => {
        this.loading = false;
        this.tableData = res.items;
        this.total = res.totalCount;
      }, error => {
        this.loading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 成绩导出
    exportScore() {
      const that = this;
      this.btnLoading = true;
      const tempUrl = `/api/excel`;
      const fileName = '成绩' + '.xlsx';
      this.GetDuanExamStudentsInput = {
        DuanExamId: this.duanExamId,
        OrganizationUnitId: this.isDeclare ? '' : this.user,
        IncludeRegisterStudent: true,
        IncludeDuanExamOfficial: true,
        IncludeLevelType: true,
        IncludeDuanType: true,
        IncludeMemberFeeType: true,
        IncludeDuanExamRequestDuans: true,
        IncludeScoreStatus: true,
        IsApproved: true,
        IncludeToScoreStatus: true,
        IncludeDuanExamFees: true,
        IsCurrentOrgStudentScore: !this.isDeclare,
        ScoreStatusCode: 'Approved',
        Sorting: 'creationTime DESC'
      };
      this.GetDuanExamStudentsInput = JSON.stringify(this.GetDuanExamStudentsInput);
      const baseUrl = WEB_CONFIG.VUE_APP_SWAGGER_HALL_BASE;
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, { reportName: 'ExamReportStudentScore', GetDuanExamStudentsInput: this.GetDuanExamStudentsInput }, baseUrl).then(res => {
        this.btnLoading = false;
      }).catch(error => {
        that.btnLoading = false;
        errorText(error).then(function(text) {
          that.$message({ type: 'error', message: text });
        });
      });
    },
    // 分页
    changePage(page) {
      this.getPageList(page);
    },
    changePageSize(pagesize) {
      this.qo.MaxResultCount = pagesize;
      this.getPageList();
    }
  }
};
</script>

<style lang="scss" scoped>
.noPadding {
  padding: 0px;
}
.top_title {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #E8E8E8;
  font-size: 16px;
  font-weight: bold;
  padding-left: 25px;
}
</style>
